#!/system/bin/sh
#mounts and chroots debian system on Android
#might need to create loop 
#busybox mknod /dev/loop0 b 7 0
#busybox mknod -m640 /dev/block/loop255 b 7 255

#to install this script you need to make system RW
#mmcblk0p5 might change so check 'mount' command
#mount -o remount,rw /dev/block/mmcblk0p5 /system
#on Lollipop run this to stop ld.so ERROR  -- unset LD_PRELOAD
dir=/storage/sdcard1/
chroot=${dir}debian
img=${dir}debian_arm.img

mounts () {
	mount -o loop -t ext4 $img $chroot
	busybox mount --bind /dev $chroot/dev
	busybox mount --bind /dev/pts $chroot/dev/pts
	busybox mount -t proc proc $chroot/proc
	busybox mount -t sysfs sysfs $chroot/sys
}

mount|grep "$chroot"&&echo "Already Mounted"|| mounts

export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
export USER=root

busybox chroot $chroot /bin/bash